package cn.bone.cloud.zuul.filter;

import com.netflix.zuul.ZuulFilter;
import com.netflix.zuul.context.RequestContext;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by Administrator on 2017/11/3.
 */
public class LogFilter extends ZuulFilter {
    @Override
    public String filterType() {
        return "post";
    }

    @Override
    public int filterOrder() {
        return 1001;
    }

    @Override
    public boolean shouldFilter() {
        return true;
    }

    @Override
    public Object run() {
        RequestContext ctx = RequestContext.getCurrentContext();
        HttpServletRequest request = ctx.getRequest();
        System.out.println("method:"+request.getMethod());
        System.out.println("url:"+request.getRequestURL());
        System.out.println("servletPath:"+request.getServletPath());
        String responseBody = ctx.getResponseBody();
        System.out.println("status:"+ctx.getResponse().getStatus());
        System.out.println("response:"+responseBody);

        return null;
    }
}
